package com.language.data_procress.language;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.webservice.webservice_line;

public class data_procress_return_language extends languages {

	public List<String> return_all() {
		String path = super.getLanguagePATH();
		JSONObject jo = new webservice_line().startService_ReturnJSON(path);
		List<String> str = new ArrayList<String>();
		try {
			JSONArray jarrayID = jo.getJSONArray("id");
			JSONArray jarrayENG = jo.getJSONArray("english");
			JSONArray jarrayTUR = jo.getJSONArray("turkish");

			for (int i = 0; i < jarrayID.length(); i++) {
				str.add(jarrayID.getString(i) + ". " + jarrayENG.getString(i)
						+ " : " + jarrayTUR.getString(i));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return str;
	}

	public languages return_Eng_Tur_byId(Integer id) {
		String path = super.getLanguagePATH() + id;
		JSONObject jo = new webservice_line().startService_ReturnJSON(path);
		languages lang = new languages();
		lang.setId(id);
		try {
			lang.setEnglish(jo.getString("english"));
			lang.setTurkish(jo.getString("turkish"));
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return lang;
	}

	public String return_English_byTurkish(String turkish) {
		String path = super.getLanguagePATH() + "indEnglishByTurkish/"
				+ turkish;
		JSONObject jo = new webservice_line().startService_ReturnJSON(path);

		try {
			return jo.getString("english");
		} catch (JSONException e) {
			return "Error:" + e.getMessage();
		}
	}

	public String return_Turkish_byEnglish(String english) {
		String path = super.getLanguagePATH() + "findTurkishByEnglish/"
				+ english;
		JSONObject jo = new webservice_line().startService_ReturnJSON(path);

		try {
			return jo.getString("turkish");
		} catch (JSONException e) {
			return "Error:" + e.getMessage();
		}

	}

	public String return_English_byId(Integer id) {
		String path = super.getLanguagePATH() + id;
		JSONObject jo = new webservice_line().startService_ReturnJSON(path);

		try {
			return jo.getString("english");
		} catch (JSONException e) {
			return "Error:" + e.getMessage();
		}
	}

	public String return_Turkish_byId(Integer id) {
		String path = super.getLanguagePATH() + id;
		JSONObject jo = new webservice_line().startService_ReturnJSON(path);

		try {
			return jo.getString("turkish");
		} catch (JSONException e) {
			return "Error:" + e.getMessage();
		}
	}

}